﻿using ActionSystem.Core;
using System;
using UnityEditor;
using UnityEngine;

namespace XMLib
{
    /// <summary>
    /// 编辑器展示自定义label
    /// </summary>
    [CustomPropertyDrawer(typeof(SlotTagAttribute))]
    public class SlotTagDrawer : PropertyDrawer
    {
        private GUIContent _label = new GUIContent("位置ID:");
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool hasDraw = false;
            //获取到定义的名称
            var names = TypeCache.GetTypesWithAttribute<SlotNameAttribute>();
            if(names.Count>0)
            {
                float labw = position.width/2;
                Rect labr = new Rect(position.position,new Vector2(labw, position.height));
                Type slotTypeName = names[0];
                var values = Enum.GetValues(slotTypeName) as int[];
                var displayNames = Enum.GetNames(slotTypeName);              
                GUI.Label(labr,"位置ID:");
                
                Rect idr = new Rect(new Vector2(labw,position.y), new Vector2(position.width - labw, position.height)) ;
                property.intValue = EditorGUI.IntPopup(idr, property.intValue, displayNames,values);
                hasDraw = true;
            }                            
            if(hasDraw==false)
                EditorGUI.PropertyField(position, property, _label);
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            return base.GetPropertyHeight(property, label);
        }
    }
}
